package net.tngou.iask.service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.math.NumberUtils;

import net.tngou.iask.dao.QuestionDao;
import net.tngou.iask.jdbc.PageUtil;
import net.tngou.iask.pojo.Answer;
import net.tngou.iask.pojo.Filter;
import net.tngou.iask.pojo.Question;
import net.tngou.iask.util.StringUtil;

public class QuestionService extends BaseService {

	/**
	 * 取得问题
	 * @param page 当前页
	 * @param size 页大小
	 * @param main 实体（）
	 * @param type 类型
	 * @param keyword 搜索关键词
	 * @return
	 */
	public PageUtil getPage(int page,int size,long main,long type,String keyword) {
		QuestionDao dao = new QuestionDao();
		return dao.getPage(page, size, main, type, keyword);
		
	}
	public PageUtil getPage(int page,int size,long main,String keyword) {
		QuestionDao dao = new QuestionDao();
		return dao.getPage(page, size, main, keyword);
		
	}
	/**
	 * 取得问题对应的 选项
	 * @param question
	 * @return
	 */
	public List<Answer> getAnswer(long question) {
		QuestionDao dao = new QuestionDao();
		return dao.getAnswer(question);
	}
	
	
	/**
	 * 取得暂且没有选择的问题
	 * @param question 问题
	 * @param type 类型
	 * @return
	 */
	public List<Answer> getNotSelectAnswer(long question,int type){
		QuestionDao dao = new QuestionDao();
		return dao.getNotSelectAnswer(question, type);
	}
	
	public PageUtil getPage(int page,int size,long main,long question,long type,String keyword) {
		QuestionDao dao = new QuestionDao();
		return dao.getPage(page, size, main, question, type, keyword);
	}
	/**
	 * 取得问题对应的 选项
	 * @param question
	 * @return
	 */
	public List<Map<String, Object>> getQuestionAnswer(long question) {
		QuestionDao dao = new QuestionDao();
		return dao.getQuestionAnswer(question);
	}
	/**
	 * 更新问题中间库
	 * @param question 问题ID
	 * @param answers 选项
	 * @param filters 过滤条件
	 */
	public void update(long question,String[] filter) {
		Long answers[]=null;
		Long filters[]=null;
	
		if(filter!=null)filters=StringUtil.StringToLong(filter);
		QuestionDao dao = new QuestionDao();
		dao.update(question, filters);
	}
	/**
	 * 取得问题列表
	 * @param main 实体（）
	 * @return
	 */
	public List<Question>  getList(long main) {
		QuestionDao dao = new QuestionDao();
		return dao.getList(main);
	}
	public List<Question>  getListNotSurvey(long main,long survey) {
		QuestionDao dao = new QuestionDao();
		return dao.getListNotSurvey(main,survey);
	}
	
	public PageUtil getPageNotQuestion(int page,int size,long main,long survey,String keyword) {
		QuestionDao dao = new QuestionDao();
		return dao.getPageNotQuestion(page, size, main, survey, keyword);
	}
	/**
	 * 取得问卷对应的问题
	 * @param survey
	 * @return
	 */
	public List<Question> getQuestion(long survey) {
		QuestionDao dao = new QuestionDao();
		return dao.getQuestion(survey);
	}
	public List<Map<String, Object>> getQuestionMap(long survey) {
		QuestionDao dao = new QuestionDao();
		return dao.getQuestionMap(survey);
	}
	/**
	 * 取得问题对应过滤条件
	 * @param question
	 * @return
	 */
	public List<Filter> getFilter(long question) {
		QuestionDao dao = new QuestionDao();
		return dao.getFilter(question);
	}
}
